<template>
	<view>
		<u-cell-group>
			<u-cell-item 
				v-for="(item,index) in applyList"
				:key="index"
				:title="item.enterprise.department"
				:label="`申请人：${item.user.name}(${item.user.mobile})`"
				@click="getDetail(item.id)">
				<view>
					<text class="color-warning" v-if="item.state == 0">待审核</text>
					<text class="color-danger" v-if="item.state == 1">已取消</text>
					<text class="color-danger" v-if="item.state == 2">已驳回</text>
					<text class="color-success" v-if="item.state == 3">已通过</text>
				</view>
			</u-cell-item>
		</u-cell-group>
		<!-- 详情 -->
		<u-popup v-model="show" mode="bottom" border-radius="14">
			<view class="u-p-30">
				<u-cell-group>
					<u-cell-item 
						:arrow="false"
						v-if="form.enterprise.parentid > 0"
						title="申请加入部门"
						:value="form.enterprise.department"
						>
					</u-cell-item>
					<u-cell-item
						:arrow="false"
						v-else
						title="申请加入客户组"
						:value="form.enterprise.name"
						>
					</u-cell-item>
					<u-cell-item
						:arrow="false"
						title="申请人"
						:value="form.user.name"
						>
					</u-cell-item>
					<u-cell-item
						:arrow="false"
						title="申请人手机"
						:value="form.user.mobile"
						>
					</u-cell-item>
					<u-cell-item
						:arrow="false"
						title="备注"
						:value="form.reason || '--'"
						>
					</u-cell-item>
				</u-cell-group>
				<view class="u-p-30 u-flex" v-if="form.state == 0">
					<view class="u-flex-1">
						<u-button type="primary" form-type="submit" @click="pass">通过</u-button>
					</view>
					<view class="u-flex-1 u-p-l-15">
						<u-button type="error" @click="show2 = true">驳回</u-button>
					</view>
				</view>
			</view>
		</u-popup>
		<!-- 驳回申请 -->
		<u-modal v-model="show2" title="请填写驳回原因" :show-cancel-button="true" @confirm="cancelPass" @cancel="show2 = false">
			<view class="slot-content">
				<view class="u-p-30">
					<u-input v-model="key" type="textarea" :border="true" />
				</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				applyList: [],
				form:{},
				key: '',
				// content: '',
				show2: false
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			getList(){
				this.$u.post('/Enterprise/BindApply/List',{
					"PageIndex":1,
					"PageSize":999,
					"Key":"",
					"enterpriseId": this.lastloginenterpriseid
				}).then((res) => {
					console.log('申请绑定客户组申请列表',res.rows.filter((item)=>item.state == 0))
					this.applyList = res.rows
				})
			},
			getDetail(id){
				this.$u.get('/Enterprise/BindApply/Detail?id='+id).then((res)=>{
					console.log('申请详情',res)
					this.form = res
					this.show = true
				})
			},
			pass(){
				uni.showModal({
					title: '您确认通过审核吗？',
					success: (res)=> {
						if (res.confirm) {
							this.$u.get('/Enterprise/BindApply/Pass?id='+this.form.id).then((res) => {
								uni.showToast({
									title: '审核成功'
								})
								this.show = false
								this.getList()
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			cancelPass(){
				this.$u.post('/Enterprise/BindApply/Cancel',{
					id: this.form.id,
					reason: this.key
				}).then((res) => {
					uni.showToast({
						title: '已驳回'
					})
					this.show2 = false
					this.getList()
				})
			}
		}
	}
</script>

<style>

</style>
